import { getLayoutProps } from "@/common/layout/getProps";
import { DeleteOutlined, DownloadOutlined, EditOutlined, PlusOutlined } from "@ant-design/icons";
import { PageContainer } from "@ant-design/pro-layout";
import {
  Button,
  Col,
  DatePicker,
  Form,
  Input,
  InputNumber, message, Modal,
  Row, Select, Space,
  Table,
  type TableColumnsType,
  type TableProps
} from "antd";
import dayjs from "dayjs";
import Router from "next/router";
import { useRouter } from "next/router";
import { type FC, type HTMLAttributes, type Key, type PropsWithChildren, useEffect, useState } from "react";
import GlobalClasses from "@/styles/globalClasses.module.scss";
import styles from "./index.module.scss";
import { useRouter as useNavigationRouter } from "next/navigation";
import { http } from "@/utils/request";

// type TableRowSelection<T> = TableProps<T>["rowSelection"];

const { confirm } = Modal;
type TableDataType = {
  field1: string;
  field2: string;
  field3: string;
  field4: string;
  field5: string;
  field6: string;
  field7: string;
  field8: string;
  field9: string;
}

interface EditableCellProps extends HTMLAttributes<HTMLElement> {
  editing: boolean;
  dataIndex: string;
  title: any;
  record: TableDataType;
  index: number;
}

// const EditableCell: FC<PropsWithChildren<EditableCellProps>> = ({
//   editing,
//   dataIndex,
//   title,
//   record,
//   index,
//   children,
//   ...restProps
// }) => {
//   const inputNumberNode = <InputNumber className={'w-full'} min={0} disabled={!isNoSelf}/>;
//   const inputNode = <Input className={'w-full'} disabled={!isNoSelf}/>;
//   return (
//     <td {...restProps}>
//       {editing ? (
//         <Form.Item
//           name={dataIndex}
//           style={{ margin: 0 }}
//           rules={[
//             {
//               required: true,
//               message: `请输入${title}!`,
//             },
//           ]}
//         >
//           {dataIndex=='selfScore'||dataIndex=='manageDepScore'||dataIndex=='groupScore'?inputNumberNode:inputNode}
//         </Form.Item>
//       ) : (
//         children
//       )}
//     </td>
//   );
// };

export const DepartmentAppraiseCU = () => {
  const { TextArea } = Input;
  const router = useRouter();
  const { query } = router;
  const { id, type,isNoSelf } = query;
  const [form] = Form.useForm();
  const [editTableData, setEditTableData] = useState<Partial<Record<string, any>>[]>([]);
  const [applicationData, setApplicationData] = useState<Partial<Record<string, any>>[]>([]);
  const [editForm] = Form.useForm()
  const [open, setOpen] = useState<boolean>(false);
  const [currentEdit, setCurrentEdit] = useState<Partial<TableDataType>>({});
  // const [selectedRowKeys, setSelectedRowKeys] = useState<Key[]>([])
  const [evaluPersionType,setEvaluPersionType] = useState(1)
  const [editIndex,setEditIndex] = useState(null);
  const [pmEvaluationObjectVos,setPmEvaluationObjectVos] = useState({});
  const [projectList,setProjectList] = useState([]);
  const [projectName,setProjectName] = useState('');
  const [projectCode,setProjectCode] = useState('');
  const isAdd = !id && !type;
  const isEdit = !!id && !type;
  const isDetail = !!id && (type === "detail");


  const editTableColumns: TableColumnsType = [
    {
      align: "center",
      title: "序号",
      width: 60,
      key: "index",
      render: (_text: string, _record, index: number) => {
        return index + 1
      }
    },
    {
      align: "center",
      title: "指标类型名称",
      width: 150,
      dataIndex: "targetTypeName"
    },
    {
      align: "center",
      title: "指标名称",
      width: 150,
      dataIndex: "targetName"
    },
    {
      align: "center",
      title: "指标定义",
      width: 200,
      dataIndex: "targetContent"
    },
    {
      align: "center",
      title: "考评标准",
      width: 200,
      dataIndex: "standard"
    },
    {
      align: "center",
      title: "权重(%)",
      width: 120,
      dataIndex: "targetWeight"
    }
  ]

  const editColumns = [
    {
      align: "center",
      title: "自评得分",
      fixed: 'right',
      width: 100,
      dataIndex: "selfScore",
      render: (_,record) => {
        return (
          <>
          {isDetail&&<span>{record.selfScore}</span>}
          {!isDetail&&
            <InputNumber className={'w-full'} placeholder="请输入" value={record.selfScore} min={0} onChange={(value) => {
              const newDataSource = editTableData.map((item) => {
                if(item.id == record.id){
                  item.selfScore = value
                  return item;
                }
                return item;
              });
              setEditTableData(newDataSource);
            }}/>
          }
          </>
        )
      }
    },
    {
      align: "center",
      title: "自评得分说明",
      fixed: 'right',
      width: 200,
      dataIndex: "selfDesc",
      render: (_,record) => {
        return (
          <>
          {isDetail&&<span>{record.selfDesc}</span>}
          {!isDetail&&
            <Input className={'w-full'} placeholder="请输入" value={record.selfDesc} onChange={(e) => {
              const newDataSource = editTableData.map((item) => {
                if(item.id == record.id){
                  item.selfDesc = e.target.value
                  return item;
                }
                return item;
              });
              setEditTableData(newDataSource);
            }}/>
          }
          </>
        )
      }
    },
  ]
  // .map(col => {
  //   return {
  //     ...col,
  //     onCell: (record) => {
  //       return {
  //         record,
  //         title:col.title,
  //         dataIndex: col.dataIndex,
  //         editing: isAdd || isEdit
  //       }
  //     }
  //   }
  // }) as TableColumnsType
  const isNoSelfColumns = [
    {
      align: "center",
      title: "互评打分",
      fixed: 'right',
      width: 120,
      dataIndex: "manageDepScore",
      render: (_,record) => {
        return (
          <>
            <InputNumber className={'w-full'} disabled={!isNoSelf} placeholder="请输入" value={record.manageDepScore} min={0} onChange={(value) => {
              const newDataSource = editTableData.map((item) => {
                if(item.id == record.id){
                  item.manageDepScore = value
                  return item;
                }
                return item;
              });
              setEditTableData(newDataSource);
            }}/>
          </>
        )
      }
    },
    {
      align: "center",
      title: "互评打分说明",
      fixed: 'right',
      width: 200,
      dataIndex: "manageDepDesc",
      render: (_,record) => {
        return (
          <>
            <Input className={'w-full'} disabled={!isNoSelf} placeholder="请输入" value={record.manageDepDesc}  onChange={(e) => {
              const newDataSource = editTableData.map((item) => {
                if(item.id == record.id){
                  item.manageDepDesc = e.target.value
                  return item;
                }
                return item;
              });
              setEditTableData(newDataSource);
            }}/>
          </>
        )
      }
    },
    {
      align: "center",
      title: "考评小组评分",
      fixed: 'right',
      width: 120,
      dataIndex: "groupScore",
      render: (_,record) => {
        return (
          <>
            <InputNumber className={'w-full'} disabled={!isNoSelf} placeholder="请输入" value={record.groupScore} min={0} onChange={(value) => {
              const newDataSource = editTableData.map((item) => {
                if(item.id == record.id){
                  item.groupScore = value
                  return item;
                }
                return item;
              });
              setEditTableData(newDataSource);
            }}/>
          </>
        )
      }
    },
    {
      align: "center",
      title: "考评小组评分说明",
      fixed: 'right',
      width: 200,
      dataIndex: "groupScoreDesc",
      render: (_,record) => {
        return (
          <>
            <Input className={'w-full'} disabled={!isNoSelf} placeholder="请输入" value={record.groupScoreDesc}  onChange={(e) => {
              const newDataSource = editTableData.map((item) => {
                if(item.id == record.id){
                  item.groupScoreDesc = e.target.value
                  return item;
                }
                return item;
              });
              setEditTableData(newDataSource);
            }}/>
          </>
        )
      }
    },
  ]
  const applicationColumns: TableColumnsType = [
    {
      align: "center",
      title: "序号",
      width: 60,
      key: "index",
      render: (_text: string, _record, index: number) => {
        return index + 1
      }
    },
    {
      align: "center",
      title: "项目名称",
      dataIndex: "itemName"
    },
    {
      align: "center",
      title: "项目内容",
      dataIndex: "itemDesc"
    },
    {
      align: "center",
      title: "完成情况",
      dataIndex: "finishDesc"
    },
    {
      align: "center",
      title: "表彰情况",
      dataIndex: "praiseDesc"
    },
    {
      align: "center",
      title: "申请分数",
      dataIndex: "reqScore"
    },
    {
      align: "center",
      title: "申请说明",
      dataIndex: "reqDesc"
    }
  ]
  const operateColumns:TableColumnsType = [
    {
      title: "操作",
      width:200,
      align:'center',
      render: (_, record,index) => {
        return (
          <>
            <Button type={'link'} onClick={()=>{
              editForm.resetFields();
              const newObj = JSON.parse(JSON.stringify(record));
              setCurrentEdit(newObj);
              getProjectItem();
              setEditIndex(index);
              editForm.setFieldsValue(applicationData.find(item => (item.itemName === record.itemName))!)
              setOpen(true);
            }}>编辑</Button>
            <Button type={'link'} danger onClick={()=>{
              if(isEdit){
                confirm({
                  title: '提示?',
                  content: '此操作将永久删除该数据，是否继续?',
                  onOk() {
                    delApplicationData(record.id);
                  },
                });
              }else{
                const newArr = JSON.parse(JSON.stringify(applicationData));
                newArr.splice(index,1);
                setApplicationData(newArr);
              }
            }}>删除</Button>
          </>
        )
      }
    }]
  // const onSelectChange = (keys: Key[]) => {
  //   console.log(keys);
  //   setSelectedRowKeys(keys)
  // }

  // const rowSelection: TableRowSelection<TableDataType> = {
  //   selectedRowKeys,
  //   onChange: onSelectChange
  // }
  const delApplicationData = async(id:string)=>{
    const res = await http.delete({
      url:'/PmEvaluObjectItem/removeEvaluObjectItem',
      params:{id:id},
    })
    if(res.code == 200){
      message.success('加减分申请项删除成功!');
      getDetailsData();
    }else{
      message.error(res.msg);
    }
  }
  const submit = async() => {
    const values = await form.validateFields()
    const hasEmpty = editTableData.some(item => !item.selfScore || !item.selfDesc);
    if(hasEmpty){
      message.error("请输入自评得分和自评得分说明!")
    }else{
      values.evaluBeginTime = dayjs(values.evaluBeginTime).format('YYYY-MM-DD');
      values.evaluEndTime = dayjs(values.evaluEndTime).format('YYYY-MM-DD');
      switch (evaluPersionType) {
        case 1:
          values.evaluPersion = dayjs(values.evaluPersion).format('YYYY');
          break;
        case 2:
          values.evaluPersion = dayjs(values.evaluPersion).format('YYYY')+ '-Q' + dayjs(dayjs(values.evaluPersion).format('YYYY-MM-DD')).quarter()
          break;
        case 3:
          values.evaluPersion = dayjs(values.evaluPersion).format('YYYY-MM');
          break;
        default:
          break;
      }
      //指标信息数组
      const targetArr = editTableData.map(item=>({
        planItemId:item.id,
        selfScore:item.selfScore,
        selfDesc:item.selfDesc,
        targetWeight:Number(item.targetWeight),
      }));
      //加减分数组
      const reqArr = applicationData.map(item=>({
        id:item.id?item.id:null,
        itemId:item.itemId,
        itemCode:item.itemCode,
        itemName:item.itemName,
        itemDesc:item.itemDesc,
        finishDesc:item.finishDesc,
        praiseDesc:item.praiseDesc,
        reqScore:item.reqScore,
        reqDesc:item.reqDesc,
      }));
      const addFormData = {
        evaluPlanId:editTableData[0].planId,
        ...values,
        pmEvaluationObjectQueries:[
          {
            objectId:'1',
            objectName:values.evaluObject,
            pmEvaluObjectTargetQueries:targetArr,
            pmEvaluObjectItemQueries:reqArr,
          }
        ]
      }
      if(isAdd){
        addSave(addFormData)
      }
      if(isEdit){
        editSave(addFormData)
      }
    }
    // else if(applicationData.length==0){
    //   message.error("请添加加减分申请!")
    // }
  }
  //新增接口
  const addSave = async(formData:object) =>{
    try {
      const res = await http.post({
        url:'/PmEvaluation/addDeptEvaluation',
        data:formData,
      })
      if(res.code == 200){
        message.success('部门评价新增成功!');
        Router.push('/performanceAppraise/departmentAppraise');
      }else{
        message.error(res.msg);
      }
    } catch (errorInfo) {
      console.log('Failed:', errorInfo);
    }
  }
  //编辑接口
  const editSave = async(formData:object) =>{
    formData.pmEvaluationObjectQueries[0].id = pmEvaluationObjectVos.id
    formData.pmEvaluationObjectQueries[0].pmEvaluObjectTargetQueries.map(item=>{
      item.id = item.planItemId
      delete item.planItemId
    })
    // formData.pmEvaluationObjectQueries[0].pmEvaluObjectItemQueries.map(item=>{
    //   item.id = item.itemId
    //   delete item.itemId
    // })
    try {
      const res = await http.post({
        url:'/PmEvaluation/updatePmEvaluation',
        data:{id,...formData,}
      })
      if(res.code == 200){
        message.success('部门评价修改成功!');
        Router.push('/performanceAppraise/departmentAppraise');
      }
    } catch (errorInfo) {
      console.log('Failed:', errorInfo);
    }
  }
  
  //新增/编辑加减分申请项
  const handleOk = async() => {
    const values = await editForm.validateFields()
    // const hasProject = applicationData.some(item=>item.itemId == values.itemId)
    // if(hasProject){

    // }
    if(values){
      values.itemName = projectName;
      values.itemCode = projectCode;
      const newData = JSON.parse(JSON.stringify(applicationData));
      if(JSON.stringify(currentEdit) === "{}"){
        newData.push(values);
      }else{
        for (const key in values) {
          if (key in newData[editIndex]) {
            newData[editIndex][key] = values[key];
          }
        }
      }
      setApplicationData(newData);
      setOpen(false);
    }
  }

  const handleCancel = () => {
    setOpen(false);
  }
  //获取指标信息
  const getPlanInfo = async(evaluYear:string,evaluFrequency:string)=>{
    try {
      const res = await http.get({
        url:'/pmEvaluPlan/qryByFrequency',
        params:{evaluYear:evaluYear,evaluFrequency:evaluFrequency,evaluType:'10'}
      })
      if(res.code == 200){
        form.setFieldValue('evaluObject',res.data.length>0?res.data[0].evaluObject:'');
        form.setFieldValue('deptLeader',res.data.length>0?res.data[0].deptLeader:'');
        setEditTableData(res.data.length>0?res.data[0].changeItemList:[]);
      }else{
        message.error(res.msg);
      }
    } catch (errorInfo) {
      console.log('Failed:', errorInfo);
    }
  }
  //根据所选考核期间，获取开始时间和结束时间
  const getDateTime = async(options:string,params:string)=>{
    try {
      const res = await http.get({
        url:'/calculateDateTools/dateIntervalCalculate',
        params:{options:options,param:params}
      })
      if(res.code == 200){
        form.setFieldValue('evaluBeginTime',dayjs(res.data.startDateTime, 'YYYY-MM-DD'));
        form.setFieldValue('evaluEndTime',dayjs(res.data.endDateTime, 'YYYY-MM-DD'));
      }else{
        message.error(res.msg);
      }
    } catch (errorInfo) {
      console.log('Failed:', errorInfo);
    }
  }
  //获取项目下拉列表
  const getProjectItem = async()=>{
    try {
      const res = await http.get({
        url:'/PmPlusMinusScoreDictionary/qryDropDownOptions',
      })
      if(res.code == 200){
        applicationData.forEach(aItem => {
          res.data.forEach(bItem => {
            bItem.id = String(bItem.id)
            if (aItem.itemId == bItem.id) {
              bItem.disabled = true;
            }
          });
        });
        setProjectList(res.data.map(item=>({value:item.id,label:item.projectName,projectDescription:item.projectDescription,code:item.projectCode,disabled:item.disabled?true:false})))
      }else{
        message.error(res.msg);
      }
    } catch (errorInfo) {
      console.log('Failed:', errorInfo);
    }
  }
  //获取部门评价详情数据
  const getDetailsData =async()=>{
    try {
      const res = await http.get({
        url:'/PmEvaluation/queryEvaluationDetail',
        params:{evaluationId:id}
      })
      if(res.code == 200){
        const data = JSON.parse(JSON.stringify(res.data));
        data.evaluBeginTime = dayjs(data.evaluBeginTime, 'YYYY-MM-DD');
        data.evaluEndTime = dayjs(data.evaluEndTime, 'YYYY-MM-DD');
        switch (data.evaluFrequency) {
          case '10'://年
          setEvaluPersionType(1);
          data.evaluPersion = dayjs().year(Number(data.evaluPersion));
            break;
          case '20'://季度
          setEvaluPersionType(2);
          const [year, quarter] = data.evaluPersion.split('-Q');// 使用 dayjs 创建一个日期对象，并设置到季度
          data.evaluPersion = dayjs().year(Number(year)).quarter(Number(quarter));
            break;
          case '30'://月
          setEvaluPersionType(3);
          const [years, month] = data.evaluPersion.split('-');
          data.evaluPersion = dayjs().year(Number(years)).month(Number(month));
            break;
          default:
            break;
        }
        setEditTableData(data.pmEvaluationObjectVos[0].pmEvaluObjectTargetVos)
        setApplicationData(data.pmEvaluationObjectVos[0].pmEvaluObjectItemVos)
        setPmEvaluationObjectVos(data.pmEvaluationObjectVos[0]);//部门评价信息
        data.evaluObject = data.pmEvaluationObjectVos[0].objectName//考核部门信息
        form.setFieldsValue(data);
      }else{
        message.error(res.msg);
      }
    } catch (errorInfo) {
      console.log('Failed:', errorInfo);
    }
  }

  useEffect(() => {
    if (isEdit || isDetail) {
      getDetailsData()
    } else {
      form.setFieldsValue({})
    }
  }, []);

  return (
    <>
      <PageContainer header={{
        title: false
      }}>
        <div className={[styles.formCard, 'mb-[20px]'].join(' ')}>
          <div className={[GlobalClasses.title, 'title'].join(" ")}>{(isEdit && !isDetail) ? "编辑" : isAdd ? "新增" : ""}部门绩效评价考核{ isDetail ? "详情" : "" }</div>

          <Form form={form} layout={"vertical"} autoComplete="off">
            <Row>
              <Col span={6}>
                <Form.Item
                  label={"单据编号"}
                  name="code"
                >
                  <Input disabled></Input>
                </Form.Item>
                <Form.Item
                  label={"考核期间"}
                  name="evaluPersion"
                  rules={[{ required: true, message: '请选择考核期间!' }]}
                >
                  <DatePicker picker={`${evaluPersionType==1?'year':evaluPersionType==2?'quarter':'month'}`} onChange={(value)=>{
                    if(form.getFieldValue().evaluFrequency){
                      getPlanInfo(dayjs(value).format('YYYY'),form.getFieldValue().evaluFrequency)
                      switch (evaluPersionType) {
                        case 1:
                          getDateTime('YEAR',dayjs(value).format('YYYY'))
                          break;
                        case 2:
                          getDateTime('QUARTER',dayjs(value).format('YYYY')+ '-Q' + dayjs(dayjs(value).format('YYYY-MM-DD')).quarter())
                          break;
                        case 3:
                          getDateTime('MONTH',dayjs(value).format('YYYY-MM'))
                          break;
                      
                        default:
                          break;
                      }
                    }else{
                      message.error('请先选择考核频次');
                    }
                  }} disabled={isDetail}/>
                </Form.Item>
                <Form.Item
                  label={"部门总监"}
                  name="deptLeader"
                >
                  <Input disabled></Input>
                </Form.Item>
              </Col>
              <Col span={6} offset={2}>
                <Form.Item
                  label={"考核名称"}
                  name="name"
                  rules={[{ required: true, message: '请输入考核名称!' }]}
                >
                  <Input placeholder={"请输入考核名称"} disabled={isDetail}></Input>
                </Form.Item>
                <Form.Item
                  label={"评价开始日期"}
                  name="evaluBeginTime"
                  rules={[{ required: true, message: '请选择评价开始日期!' }]}
                >
                  <DatePicker disabled/>
                </Form.Item>
                <Form.Item
                  label={"考核部门"}
                  name="evaluObject"
                >
                  <Input disabled></Input>
                </Form.Item>
              </Col>
              <Col span={6} offset={2}>
                <Form.Item
                  label={"考核频次"}
                  name="evaluFrequency"
                  rules={[{ required: true, message: '请选择考核频次!' }]}
                >
                  <Select placeholder="请选择考核频次" disabled={isDetail} onChange={(value)=>{
                    switch (value) {
                      case '10':
                        setEvaluPersionType(1)
                        break;
                      case '20':
                        setEvaluPersionType(2)
                        break;
                      case '30':
                        setEvaluPersionType(3)
                        break;
                      default:
                      break;
                    }
                    if(form.getFieldValue().evaluPersion){
                      getPlanInfo(dayjs(form.getFieldValue().evaluPersion).format('YYYY'),value)
                    }
                  }} options={[
                    { value: '10', label: '年度' },
                    { value: '20', label: '季度' },
                    { value: '30', label: '月度' },
                  ]} />
                </Form.Item>
                <Form.Item
                  label={"评价结束日期"}
                  name="evaluEndTime"
                  rules={[{ required: true, message: '请选择评价结束日期!' }]}
                >
                  <DatePicker disabled/>
                </Form.Item>
                {/* <Form.Item
                  label={"附件"}
                  name="field1"
                >
                  <Button type={"link"} icon={<PlusOutlined/>}>附件上传</Button>
                </Form.Item> */}
              </Col>
            </Row>

          {/* {
            !(isAdd || isEdit) ?
              null :
              (
                <Row justify={"end"} className={"mb-[20px]"}>
                  <Button type={"link"} icon={<DownloadOutlined/>}>下载模板</Button>
                  <Button type={"link"} icon={<DownloadOutlined/>}>导入</Button>
                </Row>
              )
          } */}
          {/* 指标项明细表格 */}
          {editTableData.length>0&&
            <Table
              // components={{
              //   body: {
              //     cell: EditableCell
              //   }
              // }}
              scroll={{ x: 1800 }}
              dataSource={editTableData}
              columns={isNoSelf?editTableColumns.concat(editColumns).concat(isNoSelfColumns):editTableColumns.concat(editColumns)}
              rowKey={(record) => `${record.targetId}`}
              pagination={false}>
            </Table>
          }
          
          </Form>
        </div>

        <div className={styles.formCard}>
          <div className="header">
            <div className={[GlobalClasses.title, "title"].join(" ")}>加减分申请</div>
            {
              !(isAdd || isEdit) ?
                null :
                (
                  <Row justify={"end"} className={"mb-[20px]"}>
                    <Button type={"link"} icon={<DownloadOutlined/>}>下载模板</Button>
                    <Button type={"link"} icon={<DownloadOutlined/>}>导入</Button>
                    <Space>
                      <Button type={'primary'} icon={<PlusOutlined />} onClick={() => {
                        editForm.resetFields();
                        setCurrentEdit({});
                        getProjectItem();
                        setOpen(true);
                      }}>新增</Button>
                      {/* <Button disabled={selectedRowKeys.length !== 1} type={'primary'} icon={<EditOutlined />} onClick={() => {
                        editForm.resetFields();
                        editForm.setFieldsValue(applicationData.find(item => (item.itemName === selectedRowKeys[0]))!)
                        // setCurrentEdit(applicationData.find(item => (item.itemName === selectedRowKeys[0]))!)
                        setOpen(true);
                      }}>编辑</Button>
                      <Button type={'primary'} icon={<DeleteOutlined />} danger>删除</Button> */}
                    </Space>
                  </Row>
                )
            }
          </div>
          {/* 加减分项申请表格明细 */}
          <Table
            className={'mb-[20px]'}
            rowKey={'itemName'}
            dataSource={applicationData}
            columns={isDetail?applicationColumns:applicationColumns.concat(operateColumns)}
            pagination={false}
          ></Table>

          {
            !(isAdd || isEdit) ?
              <Row justify={'end'}>
                <Button onClick={() => {
                  Router.push('/performanceAppraise/departmentAppraise');
                }}>返回</Button>
              </Row>
              :
              <Row justify={'end'}>
                <Space>
                  <Button onClick={() => {
                    Router.push('/performanceAppraise/departmentAppraise');
                  }}>取消</Button>
                  <Button>保存</Button>
                  <Button type={'primary'} onClick={submit}>提交</Button>
                </Space>
              </Row>
          }

          <Modal
            open={open}
            title={`${JSON.stringify(currentEdit) === "{}" ? "新增" : "编辑"}加减分申请`}
            afterClose={() => editForm.resetFields()}
            onOk={handleOk}
            onCancel={handleCancel}
            okText={'提交'}
            cancelText={'取消'}
            footer={(_, { OkBtn, CancelBtn }) => (
              <>
                <CancelBtn />
                <OkBtn />
              </>
            )}
          >
            <Form form={editForm} initialValues={{}} labelCol={{span: 4}} autoComplete="off">
              <Form.Item
                label={'项目名称'}
                name={'itemId'}
                rules={[{ required: true, message: '请选择项目名称!' }]}
              >
                <Select
                  placeholder={"请选择项目名称"}
                  options={projectList}
                  onChange={(value,option)=>{
                    setProjectName(option.label);
                    setProjectCode(option.code);
                    editForm.setFieldValue('itemDesc',option.projectDescription)
                    editForm.setFieldValue('finishDesc',option.projectDescription)
                    editForm.setFieldValue('praiseDesc',option.projectDescription)
                    editForm.setFieldValue('reqScore',100)
                    editForm.setFieldValue('reqDesc',option.projectDescription)
                  }}
                ></Select>
              </Form.Item>
              <Form.Item
                label={'项目内容'}
                name={'itemDesc'}
              >
                <Input disabled placeholder={"请输入项目内容"}></Input>
              </Form.Item>
              <Form.Item
                label={'完成情况'}
                name={'finishDesc'}
                rules={[{ required: true, message: '请输入完成情况!' }]}
              >
                <Input placeholder={"请输入完成情况"}></Input>
              </Form.Item>
              <Form.Item
                label={'表彰情况'}
                name={'praiseDesc'}
                rules={[{ required: true, message: '请输入表彰情况!' }]}
              >
                <Input placeholder={"请输入表彰情况"}></Input>
              </Form.Item>
              <Form.Item
                label={'申请分数'}
                name={'reqScore'}
                rules={[{ required: true, message: '请输入申请分数!' }]}
              >
                <InputNumber className={'w-full'} placeholder={"请输入申请分数"} min={0} max={100}></InputNumber>
              </Form.Item>
              <Form.Item
                label={'申请说明'}
                name={'reqDesc'}
                rules={[{ required: true, message: '请输入申请说明!' }]}
              >
                <TextArea showCount maxLength={200} placeholder="请输入申请说明" />
              </Form.Item>
            </Form>
          </Modal>
        </div>
      </PageContainer>
    </>
  )
}

export const getServerSideProps = getLayoutProps;
export default DepartmentAppraiseCU;
